package com.ruoyi.web.controller.help;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.help.domain.Transfer;
import com.ruoyi.help.service.ITransferService;
import com.ruoyi.help.vo.TransferVo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 问题移交Controller
 *
 * @author ruoyi
 * @date 2023-05-19
 */
@RestController
@RequestMapping("/system/transfer")
public class TransferController extends BaseController {
    @Autowired
    private ITransferService transferService;

    /**
     * 查询问题移交列表
     */
    @PreAuthorize("@ss.hasPermi('system:transfer:list')")
    @GetMapping("/list")
    public TableDataInfo list(Transfer transfer) {
        startPage();
        List<Transfer> list = transferService.selectTransferList(transfer);
        return getDataTable(list);
    }

    /**
     * 导出问题移交列表
     */
    @PreAuthorize("@ss.hasPermi('system:transfer:export')")
    @Log(title = "问题移交", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Transfer transfer) {
        List<Transfer> list = transferService.selectTransferList(transfer);
        ExcelUtil<Transfer> util = new ExcelUtil<Transfer>(Transfer.class);
        util.exportExcel(response, list, "问题移交数据");
    }

    /**
     * 获取问题移交详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:transfer:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(transferService.selectTransferById(id));
    }

    /**
     * 新增问题移交
     */
    @PreAuthorize("@ss.hasPermi('system:transfer:add')")
    @Log(title = "问题移交", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TransferVo transferVo){
        return toAjax(transferService.insertTransfer(transferVo));
    }

    /**
     * 修改问题移交
     */
    @PreAuthorize("@ss.hasPermi('system:transfer:edit')")
    @Log(title = "问题移交", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Transfer transfer) {
        return toAjax(transferService.updateTransfer(transfer));
    }

    /**
     * 删除问题移交
     */
    @PreAuthorize("@ss.hasPermi('system:transfer:remove')")
    @Log(title = "问题移交", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(transferService.deleteTransferByIds(ids));
    }
}
